<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script>
        var num = 0;

        function f() {
            var tb = document.getElementById("tb");
            var un = document.getElementById("un");
            var pwd = document.getElementById("pwd");
            var sex = document.getElementsByName("sex");
            for (var i = 0; i < sex.length; i++) {
                if (sex[i].checked == true) {
                    sex =sex[i].value;
                    break;
                }else if (i==sex.length-1){
                    sex="";
                }
            }
            tb.innerHTML += " <tr>\n" +
                "        <th>" + (++num) + "</th>\n" +
                "        <th>" + un.value + "</th>\n" +
                "        <th>" + pwd.value + "</th>\n" +
                "        <th>" + sex + "</th>\n" +
                "    </tr>"
        }
    </script>
</head>
<body>
用户名:<input id="un" type="text"/>
密码:<input id="pwd" type="password"/>
性别:<input type="radio" name="sex" value="男"/>男<input type="radio" name="sex" value="女"/>女
<input type="button" value="添加到表格" onclick="f()"/>
<table id="tb" border="1" cellpadding="0" cellspacing="0" width="30%">
    <tr>
        <th>序号</th>
        <th>用户名</th>
        <th>密码</th>
        <th>性别</th>
    </tr>
</table>
</body>
</html>